package com.zlc.study.controller;

import cn.hutool.core.date.DateUtil;
import com.zlc.study.service.ChatAssistant;
import com.zlc.study.service.ChatMemoryAssistant;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class ChatMemoryController {
    @Resource(name ="chat")
    private ChatAssistant chatAssistant;

    @Resource(name = "chatMessageWindowChatMemory")
    private ChatMemoryAssistant chatMessageWindowChatMemory;

    @Resource(name = "chatTokenWindowChatMemory")
    private ChatMemoryAssistant chatTokenWindowChatMemory;

    @GetMapping(value = "/chatmemory/test1")
    public String chat(){
        String answer1 = chatAssistant.chat("你好，我是照着抄");
        System.out.println("answer1返回结果："+answer1);

        String answer2 = chatAssistant.chat("我的名字是什么？");
        System.out.println("answer2返回结果："+answer1);
        return "success : "+ DateUtil.now()+"<br> \n\n answer01: "+answer1+"<br> \n\n answer02: "+answer2;
    }

    @GetMapping("/chatmemory/test2")
    public String chat2(){
        chatMessageWindowChatMemory.chatWithChatMemory(1L,"你好，我的名字是zzc");
        String answer1 = chatMessageWindowChatMemory.chatWithChatMemory(1L,"我的名字是？");
        System.out.println("answer1: "+answer1);

        chatMessageWindowChatMemory.chatWithChatMemory(2L,"你好，我是zlc");
        String answer2 = chatMessageWindowChatMemory.chatWithChatMemory(2L,"我的名字是什么");
        System.out.println("answer2: "+answer2);
        return "chatMessageWindowChatMemory success : "
                + DateUtil.now()+"<br> \n\n answer1: "+answer1+"<br> \n\n answer2: "+answer2;
    }

    @GetMapping(value = "/chatmemory/test3")
    public String chat3(){
        chatTokenWindowChatMemory.chatWithChatMemory(1L,"你好，我的名字是zc");
        String answer1 = chatTokenWindowChatMemory.chatWithChatMemory(1L,"我叫什么？");
        System.out.println("answer1: "+answer1);

        chatTokenWindowChatMemory.chatWithChatMemory(2L,"你好，我的名字是zcl");
        String answer2 = chatTokenWindowChatMemory.chatWithChatMemory(2L,"我叫什么？");
        System.out.println("answer2: "+answer2);
        return "chatTokenWindowChatMemory success : "
                + DateUtil.now()+"<br> \n\n answer1: "+answer1+"<br> \n\n answer2: "+answer2;
    }
}
